package com.richard.base.route

import com.richard.base.module.BusMsg
import com.richard.base.module.NavigateBean
import me.yokeyword.fragmentation.ISupportFragment
import me.yokeyword.fragmentation.SupportActivity
import me.yokeyword.fragmentation.SupportFragment
import org.greenrobot.eventbus.EventBus


/**
 * 业务module级别 的 路由跳转
 */
object KsRouterHelper {

    /**
     * ##############################  启动器 start #########################
     */
    fun homeProvider():Any? {
        return KsRouter.instance.build(RouterPath.STARTER.HOME_PROVIDER)
                .navigation()
    }

    fun mainProvider():Any? {
        return KsRouter.instance.build(RouterPath.STARTER.MAIN_PROVIDER)
            .navigation()
    }

    fun mineProvider():Any? {
        return KsRouter.instance.build(RouterPath.STARTER.MINE_PROVIDER)
            .navigation()
    }

    fun loginProvider():Any? {
        return KsRouter.instance.build(RouterPath.STARTER.LOGIN_PROVIDER)
            .navigation()
    }


    /**
     * ##############################  启动器 end #########################
     */

    fun appConfig(): Any = KsRouter.instance.build(RouterPath.Home.HOME_APP_CONFIG).navigation()

    fun homePoetryDetail(poetryId : Int){
        var fragment : SupportFragment = KsRouter.instance
            .build(RouterPath.Home.HOME_POETRY_DETAIL)
            .withInt(RouterExtra.ID, poetryId)
            .navigation() as SupportFragment

        val navigateBean = NavigateBean(RouterPath.Home.HOME_POETRY_DETAIL, fragment)
        navigateBean.launchMode = ISupportFragment.SINGLETASK
        EventBus.getDefault().post(BusMsg(BusMsg.PAGE_START, navigateBean))
    }

    fun getHomeRecFragment(): SupportFragment {
        return KsRouter.instance
            .build(RouterPath.Home.HOME_REC_PIC)
            .navigation() as SupportFragment
    }

    fun getMineFragment(): SupportFragment {
        return KsRouter.instance
            .build(RouterPath.Mine.KS_MINE_PAGER)
            .navigation() as SupportFragment
    }

    /**
     * 分发路由
     *
     * @param activity
     * @param navigateBean
     */
    fun dispatcher(activity: SupportActivity, navigateBean: NavigateBean) {

        activity.start(navigateBean.fragment, navigateBean.launchMode)
    }

}

